package net.xdclass.exception;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.util.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author guangyang
 * @since 2023-01-10
 **/
/*
@ControllerAdvice
@Slf4j
public class CustomExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public JsonData hander(Exception e){
        */
/*instanceof是Java中的二元运算符，左边是对象，右边是类；当对象是右边类或子类所创建对象时，返回true；否则，返回false。*//*

        //判断是不是自定义异常
        if (e instanceof BizException){
            BizException bizException= (BizException) e;
            log.error("[业务异常 {}]",bizException.getMsg(),e);
            return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
        }else {
            log.error("[系统业务异常 {}]",e.getMessage(),e);
            return JsonData.buildError("全局异常，错误未知");
        }
    }
}
*/
